﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;

namespace RM2012Mobile
{
    public class TCPIP
    {
        public void createStream()
        {
            try
            {
                EndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.150.1"), 500);
                Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.Connect(endPoint);
                if (socket.Connected)
                {
                    //XML data
                    string xmlData = "<menu>";
                    xmlData += "<item>" + "Lẩu gà" + "</item>";
                    xmlData += "<item>" + "Lẩu bò" + "</item>";
                    xmlData += "<item>" + "Cá hấp bia" + "</item>";
                    xmlData += "<item>" + "Lẩu dê" + "</item>";
                    xmlData += "<item>" + "Rượt XO" + "</item>";
                    xmlData += "</menu>";
                    socket.Send(Encoding.Unicode.GetBytes(xmlData));

                    //Receive data from Server
                    byte[] buffer = new byte[int.MaxValue];
                    socket.Receive(buffer, SocketFlags.None);
                    string strReceived = Encoding.Unicode.GetString(buffer, 0, buffer.Length);
                    MessageBox.Show(strReceived);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
